package com.example.myapplication.database;

import com.example.myapplication.App;
import com.example.myapplication.dao.DaoMaster;
import com.example.myapplication.dao.DaoSession;

public class GreenDaoManager {

    private static GreenDaoManager mInstance;
    private DaoMaster daoMaster;//它以一定模式来管理我们Dao类中的数据对象，并创建DaoSession
    private DaoSession daoSession;//他负责创建和管理Dao

    public GreenDaoManager(){
        if (mInstance==null){
            DaoMaster.DevOpenHelper devOpenHelper=new DaoMaster.DevOpenHelper(App.getInstance(),"mydb");
            daoMaster=new DaoMaster(devOpenHelper.getWritableDb());
            daoSession=daoMaster.newSession();
        }
    }



    public static GreenDaoManager getmInstance(){
        if (mInstance==null){
            synchronized (GreenDaoManager.class){
                if (mInstance==null){
                    mInstance=new GreenDaoManager();
                }
            }
        }
        return mInstance;
    }

    public DaoMaster getDaoMaster() {
        return daoMaster;
    }

    public void setDaoMaster(DaoMaster daoMaster) {
        this.daoMaster = daoMaster;
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }

    public void setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
    }


}
